package flex.cc.basicinformation.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;

import flex.cc.PublicUtil;
import flex.cc.base.dto.LoginAuthDto;
import flex.cc.basicinformation.entity.ServiceConfigEntity;
import flex.cc.basicinformation.entity.ValueAddedServiceProviderEntity;
import flex.cc.basicinformation.service.PackageConfigExportService;
import flex.cc.basicinformation.service.ServiceConfigService;
import flex.cc.basicinformation.service.StoreActivityConfigService;
import flex.cc.basicinformation.service.StorePackageConfigService;
import flex.cc.basicinformation.service.ValueAddedServiceProviderService;
import flex.cc.common.utils.OrderNoGenerateUtil;
import flex.cc.core.support.BaseController;
import flex.cc.core.utils.RequestUtil;
import flex.cc.store.dto.entity.StoreActivityConfigEntity;
import flex.cc.store.dto.entity.StorePackageConfigEntity;
import flex.cc.system.service.DictCodeService;
import flex.cc.util.DateUtil;
import flex.cc.util.FileDownloadUtil;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 
 * @author R
 * 2022年02月23日 13:35:02
 * @desc 服务包配置管理：查询、导出
 */
@RestController
@RequestMapping(value = "/basic/packageConfig")
public class PackageConfigController extends BaseController{

	@Resource
	private StorePackageConfigService packageConfigService;
	@Resource
	private StoreActivityConfigService activityConfigService;
	@Resource
	private PackageConfigExportService packageConfigExportService;
	@Resource
	private ValueAddedServiceProviderService providerService;
	@Resource
	private ServiceConfigService serviceConfigService;
	@Resource
	private DictCodeService dictCodeService;
    @Autowired
    private OrderNoGenerateUtil orderNoGenerateUtil;

	@PostMapping(value = "/queryListWithPage")
    @ApiOperation(httpMethod = "POST", value = "查询服务包配置列表")
    public Wrapper<IPage<StorePackageConfigEntity>> queryOrderListWithPage(@ApiParam(name = "storePackageConfig", value = "服务包配置信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("查询服务包配置列表storePackageConfig={}", reqVo);
        StorePackageConfigEntity storePackageConfigVo = initVo(reqVo);
        IPage<StorePackageConfigEntity> page = packageConfigService.queryPackageListWithPage(storePackageConfigVo);
        return WrapMapper.ok(page);
    }

    /**
     * @desc 初始化构建查询VO对象
     */
    public StorePackageConfigEntity initVo(Map<String, Object> reqVo) {
    	StorePackageConfigEntity storePackageConfigVo = new StorePackageConfigEntity();
    	storePackageConfigVo.setConfigCode( PublicUtil.isNotEmpty(reqVo.get("configCode")) ? reqVo.get("configCode").toString() : null );
    	storePackageConfigVo.setConfigName( PublicUtil.isNotEmpty(reqVo.get("configName")) ? reqVo.get("configName").toString() : null );
    	storePackageConfigVo.setStartTime( PublicUtil.isNotEmpty(reqVo.get("startTime")) ? reqVo.get("startTime").toString() : null );
    	storePackageConfigVo.setEndTime( PublicUtil.isNotEmpty(reqVo.get("endTime")) ? reqVo.get("endTime").toString() : null );
    	storePackageConfigVo.setPageNum( Integer.parseInt(String.valueOf(reqVo.get("pageNum"))) );
    	storePackageConfigVo.setPageSize( Integer.parseInt(String.valueOf(reqVo.get("pageSize"))) );
    	return storePackageConfigVo;
    }
    
	@PostMapping(value = "/queryActivityListWithPage")
    @ApiOperation(httpMethod = "POST", value = "查询服务包内容列表")
    public Wrapper<IPage<StoreActivityConfigEntity>> queryActivityListWithPage(@ApiParam(name = "storeActivityConfig", value = "服务包内容信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("查询服务包内容列表storeActivityConfig={}", reqVo);
        StoreActivityConfigEntity storeActivityConfigEntity = new StoreActivityConfigEntity();
        storeActivityConfigEntity.setConfigCode(PublicUtil.isNotEmpty(reqVo.get("configCode")) ? reqVo.get("configCode").toString() : null);
        storeActivityConfigEntity.setPageNum( Integer.parseInt(String.valueOf(reqVo.get("pageNum"))) );
        storeActivityConfigEntity.setPageSize( Integer.parseInt(String.valueOf(reqVo.get("pageSize"))) );
        IPage<StoreActivityConfigEntity> page = activityConfigService.queryActivityListWithPage(storeActivityConfigEntity);
        return WrapMapper.ok(page);
    }    
	
    @PostMapping(value = "/getConfigInfo")
    @ApiOperation(httpMethod = "POST", value = "根据configCode获取服务包配置信息")
    public Wrapper<String> getConfigInfo(@ApiParam(name = "StorePackageConfigEntity", value = "获取服务包配置信息")
    @RequestBody StorePackageConfigEntity storePackageConfigEntity) {
    	Map<String, Object> result = new HashMap<String, Object>();
        logger.info("根据configCode获取服务包配置信息  storePackageConfigEntity={}", storePackageConfigEntity);
        Map<String, Object> paramMap = new HashMap<String, Object>();
        
        paramMap.put("configCode", storePackageConfigEntity.getConfigCode());
        List<StorePackageConfigEntity> packageConfigList = packageConfigService.queryPackageConfig(paramMap);
        if(packageConfigList.size()>0){
        	StorePackageConfigEntity packageConfigEntity = packageConfigList.get(0);
        	result.put("configCode", packageConfigEntity.getConfigCode());
        	result.put("configNameStr", packageConfigEntity.getConfigName());
        	result.put("packageType", packageConfigEntity.getPackageType());
        	result.put("price", packageConfigEntity.getPackagePrice());
        	
        	return WrapMapper.ok(JSON.toJSONString(result));
        }
        return null;
    }
    
    @PostMapping(value = "/saveConfigInfo")
    @ApiOperation(httpMethod = "POST", value = "保存服务包配置信息")
    public Wrapper<String> saveConfigInfo(@ApiParam(name = "StorePackageConfigEntity", value = "保存服务包配置信息")
    @RequestBody StorePackageConfigEntity storePackageConfigEntity) {
    	Map<String, Object> result = new HashMap<String, Object>();
    	try {
    		//获取当前用户信息
        	LoginAuthDto loginUser = RequestUtil.getLoginUser();
        	//获取当前时间
        	Date currentDate = new Date();
        	
        	String configCode = orderNoGenerateUtil.getPackageConfigCode();
        	
        	//如果新增配置信息时，服务包配置编码不为空，则属于先保存服务包内容 再保存的服务包配置  
        	//storePackageConfigEntity.getConfigCode() 为服务包内容中暂存的服务包配置编码 再保存配置信息时，
        	//更新服务包内容中的归属服务包配置编码
        	if(PublicUtil.isNotEmpty(storePackageConfigEntity.getConfigCode())){
        		Map<String, Object> paramMap = new HashMap<String, Object>();
        		paramMap.put("tempConfigCode", storePackageConfigEntity.getConfigCode());
        		paramMap.put("configCode", configCode);
        		activityConfigService.updateByParam(paramMap);
        	}
        	
        	storePackageConfigEntity.setConfigCode(configCode);
        	storePackageConfigEntity.setCreater(loginUser.getUserCode());
        	storePackageConfigEntity.setCreateTime(currentDate);
        	storePackageConfigEntity.setUpdater(loginUser.getUserCode());
        	storePackageConfigEntity.setUpdateTime(currentDate);
        	packageConfigService.insert(storePackageConfigEntity);
        	
        	result.put("responseMsg", "服务包配置保存成功");
		} catch (Exception e) {
			result.put("responseMsg", "服务包配置保存异常");
		}
    	return WrapMapper.ok(JSON.toJSONString(result));
    }
    
    @PostMapping(value = "/updateConfigInfo")
    @ApiOperation(httpMethod = "POST", value = "更新服务包配置信息")
    public Wrapper<String> updateConfigInfo(@ApiParam(name = "StorePackageConfigEntity", value = "更新服务包配置信息")
    @RequestBody StorePackageConfigEntity storePackageConfigEntity) {
    	Map<String, Object> result = new HashMap<String, Object>();
    	try {
    		//获取当前用户信息
        	LoginAuthDto loginUser = RequestUtil.getLoginUser();
        	//获取当前时间
        	Date currentDate = DateUtil.stringToDate(DateUtil.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss");
        	
        	Map<String, Object> reqVo = new HashMap<String, Object>();
        	reqVo.put("configCode", storePackageConfigEntity.getConfigCode());
        	reqVo.put("configName", storePackageConfigEntity.getConfigName());
        	reqVo.put("packagePrice", storePackageConfigEntity.getPackagePrice());
        	reqVo.put("packageType", storePackageConfigEntity.getPackageType());
        	reqVo.put("updater", loginUser.getUserCode());
        	reqVo.put("updateTime", currentDate);
        	
        	packageConfigService.updateByParam(reqVo);
        	
        	result.put("responseMsg", "服务包配置更新成功");
		} catch (Exception e) {
			result.put("responseMsg", "服务包配置更新异常");
		}
    	return WrapMapper.ok(JSON.toJSONString(result));
    }
    
   @PostMapping(value = "/modifyRuleStatus")
   @ApiOperation(httpMethod = "POST", value = "根据configCode切换规则状态")
   public Wrapper<Boolean> modifyRuleStatus(@ApiParam(name = "StorePackageConfigEntity", value = "规则启用/禁用")
                                                @RequestBody StorePackageConfigEntity storePackageConfigEntity) {
       logger.info("根据configCode切换规则状态storePackageConfigEntity={}", storePackageConfigEntity);
       Map<String, Object> paramMap = new HashMap<String, Object>();
       //获取当前用户信息
   	   LoginAuthDto loginUser = RequestUtil.getLoginUser();
       paramMap.put("configCode", storePackageConfigEntity.getConfigCode());
       paramMap.put("status", storePackageConfigEntity.getStatus());
       paramMap.put("updater", loginUser.getLoginName());
       paramMap.put("updateTime", new Date());
       int result = packageConfigService.updateByParam(paramMap);
       return handleResult(result>0);
   }
    
    @PostMapping(value = "/exportAll")
    @ApiOperation(httpMethod = "POST", value = "服务包全部导出")
    public void exportAll(HttpServletRequest request, HttpServletResponse response,
                          @ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo){
        logger.info("服务包全部导出requestVo={}", reqVo);
        StorePackageConfigEntity storePackageConfigVo = initVo(reqVo);
        String fileParentPath = System.getProperty("user.dir") + File.separator + "package" + File.separator + System.currentTimeMillis();
        String fileName = "服务包配置列表";
        packageConfigExportService.downLoad(request, response, storePackageConfigVo, fileParentPath, fileName);
        String filepath = fileParentPath + File.separator + fileName + ".xlsx";
        FileDownloadUtil.downloadByFilepath(request, response, filepath);
    }
    
    @PostMapping(value = "/queryValidProviderList")
    @ApiOperation(httpMethod = "POST", value = "获取服务商下拉框数据")
    public Wrapper<String> queryValidProviderList() {
    	Map<String, Object> result = new HashMap<String, Object>();
    	try {
    		List<ValueAddedServiceProviderEntity> providerEntityList = providerService.queryValidProviderList();
        	result.put("responseCode", "00");
        	result.put("responseData", providerEntityList);
		} catch (Exception e) {
			result.put("responseCode", "11");
		}
    	return WrapMapper.ok(JSON.toJSONString(result));
    }
    
    @PostMapping(value = "/queryActivityList/{configCode}/{provider}")
    @ApiOperation(httpMethod = "POST", value = "根据服务商获取服务项目下拉框数据")
    public Wrapper<String> queryActivityList(@ApiParam(name = "reqVo", value = "请求信息") @PathVariable String configCode,
    		@ApiParam(name = "reqVo", value = "请求信息") @PathVariable String provider){
    	Map<String, Object> result = new HashMap<String, Object>();
        try {
        	//获取该服务商当前服务包配置中已被选过的服务项目 
        	Map<String, Object> reqVo = new HashMap<String, Object>();
        	reqVo.put("configCode", configCode);
        	reqVo.put("provider", provider);
        	List<StoreActivityConfigEntity> activityConfigList = activityConfigService.queryActivityConfig(reqVo);
        	List<String> selectedServiceList = new ArrayList<String>();
        	for (int i = 0; i < activityConfigList.size(); i++) {
        		StoreActivityConfigEntity activityConfigEntity = activityConfigList.get(i);
        		selectedServiceList.add(activityConfigEntity.getActivityCode());
			}
        	
        	//获取该服务商配置中未被选中过的服务项目
        	Map<String, Object> params = new HashMap<String, Object>();
        	params.put("serviceId", reqVo.get("provider"));
        	if(selectedServiceList.size()>0){
        		params.put("selectedServiceList", selectedServiceList);
        	}
        	List<ServiceConfigEntity> serviceConfigEntityList = serviceConfigService.queryServiceByProvider(params);
        	result.put("responseCode", "00");
        	result.put("responseData", serviceConfigEntityList);
		} catch (Exception e) {
			result.put("responseCode", "11");
		}
    	return WrapMapper.ok(JSON.toJSONString(result));
    }
    
    @PostMapping(value = "/deleteActivity/{type}/{code}")
    @ApiOperation(httpMethod = "POST", value = "未保存服务包配置但关闭页面 如果暂存了服务内容 需删除已暂存的服务内容")
    public Wrapper<String> deleteActivity(@ApiParam(name = "reqVo", value = "请求信息") @PathVariable String type,@ApiParam(name = "reqVo", value = "请求信息") @PathVariable String code){
    	Map<String, Object> result = new HashMap<String, Object>();
        String responseMsg = "";
    	try {
        	Map<String, Object> reqVo = new HashMap<String, Object>();
        	if(type.equals("list")){
        		//删除暂存服务内容列表
        		reqVo.put("configCode", code);
        		responseMsg = "暂存的服务包内容已删除";
        	}else{
        		//删除单单挑服务内容
        		reqVo.put("id", code);
        		responseMsg = "服务包内容删除成功";
        	}
        	activityConfigService.deleteActivity(reqVo);
        	result.put("responseCode", "00");
        	result.put("responseMsg", responseMsg);
		} catch (Exception e) {
			result.put("responseCode", "11");
			result.put("responseMsg", "服务包内容删除异常");
		}
    	return WrapMapper.ok(JSON.toJSONString(result));
    }
    
    @PostMapping(value = "/getActivityInfo/{activityId}")
    @ApiOperation(httpMethod = "POST", value = "根据主键获取服务内容信息")
    public Wrapper<String> getActivityInfo(@ApiParam(name = "reqVo", value = "请求信息") @PathVariable String activityId){
    	Map<String, Object> result = new HashMap<String, Object>();
    	try {
        	Map<String, Object> reqVo = new HashMap<String, Object>();
        	reqVo.put("id", activityId);
        	List<StoreActivityConfigEntity>  activityConfigList = activityConfigService.queryActivityConfig(reqVo);
        	if(activityConfigList.size()>0){
        		result.put("responseCode", "00");
        		StoreActivityConfigEntity activityConfigEntity = activityConfigList.get(0);
        		
        		Map<String, Object> params = new HashMap<String, Object>();
        		params.put("serviceId", activityConfigEntity.getProvider());
            	params.put("serviceCode", activityConfigEntity.getActivityCode());
            	ServiceConfigEntity serviceConfigEntity = serviceConfigService.getOneByParams(params);
            	if(PublicUtil.isNotEmpty(serviceConfigEntity)){
            		String serviceType = serviceConfigEntity.getServiceType();
                	if(serviceType.equals("2")||serviceType.equals("3")){ //医护类、咨询类
                		result.put("activityType", "1");
                	}else if(serviceType.equals("4")){ //代驾类
                		result.put("activityType", "2");
                	}else{ //到店类
                		result.put("activityType", "3");
                	}
            	}
        		
        		result.put("provider", activityConfigEntity.getProvider());
            	result.put("activityName", activityConfigEntity.getActivityCode()+"-"+activityConfigEntity.getActivityName());
            	result.put("count", activityConfigEntity.getCount());
            	result.put("usageCount", activityConfigEntity.getUsageCount());
            	result.put("formCode", activityConfigEntity.getFormCode());
            	result.put("validityPeriod", activityConfigEntity.getValidityPeriod());
            	String specialRule = activityConfigEntity.getSpecialRule();
            	
            	if(PublicUtil.isNotEmpty(specialRule)){
            		String[] specialRuleArr = specialRule.split(",");
            		result.put("specialRule", specialRuleArr);
            	}else{
            		String[] specialRuleArr = {};
            		result.put("specialRule", specialRuleArr);
            	}
        	}else{
        		result.put("responseCode", "11");
            	result.put("responseMsg", "无法获取服务包内容信息，请联系管理员");
        	}
		} catch (Exception e) {
			result.put("responseCode", "11");
			result.put("responseMsg", "服务包内容删除异常");
		}
    	return WrapMapper.ok(JSON.toJSONString(result));
    }
    
    @PostMapping(value = "/saveActivityInfo")
    @ApiOperation(httpMethod = "POST", value = "保存服务包内容")
    public Wrapper<String> saveActivityInfo(@ApiParam(name = "StoreActivityConfigEntity", value = "保存服务包内容信息")
    @RequestBody StoreActivityConfigEntity storeActivityConfigEntity) {
    	Map<String, Object> result = new HashMap<String, Object>();
    	try {
    		//获取当前用户信息
        	LoginAuthDto loginUser = RequestUtil.getLoginUser();
        	//获取当前时间
        	Date currentDate = new Date();
        	String activityNameStr = storeActivityConfigEntity.getActivityName();
        	if(PublicUtil.isNotEmpty(activityNameStr)){
        		String[] activityNameArr = activityNameStr.split("-");
            	storeActivityConfigEntity.setActivityCode(activityNameArr[0]);
            	storeActivityConfigEntity.setActivityName(activityNameArr[1]);
        	}
        	
        	storeActivityConfigEntity.setCreater(loginUser.getUserCode());
        	storeActivityConfigEntity.setCreateTime(currentDate);
        	storeActivityConfigEntity.setUpdater(loginUser.getUserCode());
        	storeActivityConfigEntity.setUpdateTime(currentDate);
        	activityConfigService.insert(storeActivityConfigEntity);
        	
        	result.put("responseMsg", "服务包内容保存成功");
		} catch (Exception e) {
			result.put("responseMsg", "服务包内容保存异常");
		}
    	return WrapMapper.ok(JSON.toJSONString(result));
    }
    
    
    @PostMapping(value = "/updateActivityInfo")
    @ApiOperation(httpMethod = "POST", value = "更新服务包内容")
    public Wrapper<String> updateActivityInfo(@ApiParam(name = "StoreActivityConfigEntity", value = "更新服务包内容信息")
    @RequestBody StoreActivityConfigEntity storeActivityConfigEntity) {
    	Map<String, Object> result = new HashMap<String, Object>();
    	try {
    		//获取当前用户信息
        	LoginAuthDto loginUser = RequestUtil.getLoginUser();
        	//获取当前时间
        	Date currentDate = DateUtil.stringToDate(DateUtil.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss");
        	
        	Map<String, Object> paramMap = new HashMap<String, Object>();
        	paramMap.put("id", storeActivityConfigEntity.getId());
        	paramMap.put("tempConfigCode", storeActivityConfigEntity.getConfigCode());
        	
        	String activityNameStr = storeActivityConfigEntity.getActivityName();
        	String provider = storeActivityConfigEntity.getProvider();
        	if(PublicUtil.isNotEmpty(activityNameStr)){
        		String[] activityNameArr = activityNameStr.split("-");
            	paramMap.put("activityName", activityNameArr[1]);
            	paramMap.put("activityCode", activityNameArr[0]);
            	
            	Map<String, Object> params = new HashMap<String, Object>();
            	params.put("serviceId", provider);
            	params.put("serviceCode", activityNameArr[0]);
            	List<ServiceConfigEntity> serviceConfigEntityList = serviceConfigService.queryServiceByProvider(params);
            	if(serviceConfigEntityList.size()>0){
            		ServiceConfigEntity serviceConfigEntity = serviceConfigEntityList.get(0);
            		String activityType = serviceConfigEntity.getServiceType();
            		paramMap.put("activityType", activityType);
            	}
        	}
        	
        	paramMap.put("count", storeActivityConfigEntity.getCount());
        	paramMap.put("usageCount", storeActivityConfigEntity.getUsageCount());
        	paramMap.put("provider", storeActivityConfigEntity.getProvider());
        	paramMap.put("validityPeriod", storeActivityConfigEntity.getValidityPeriod());
        	paramMap.put("formCode", storeActivityConfigEntity.getFormCode());
        	paramMap.put("specialRule", storeActivityConfigEntity.getSpecialRule());
        	paramMap.put("updater", loginUser.getUserCode());
        	paramMap.put("updateTime", currentDate);
        	
        	activityConfigService.updateByParam(paramMap);
        	
        	result.put("responseMsg", "服务包内容更新成功");
		} catch (Exception e) {
			result.put("responseMsg", "服务包内容更新异常");
		}
    	return WrapMapper.ok(JSON.toJSONString(result));
    }
    
    
    
    @PostMapping(value = "/checkConfigName/{configCode}/{configName}")
    @ApiOperation(httpMethod = "POST", value = "判断服务包名称是否重复")
    public Wrapper<String> checkConfigName(@ApiParam(name = "reqVo", value = "请求信息") @PathVariable String configCode,
    		@ApiParam(name = "reqVo", value = "请求信息") @PathVariable String configName){
    	Map<String, Object> result = new HashMap<String, Object>();
        try {
        	Map<String, Object> params = new HashMap<String, Object>();
        	params.put("configName", configName);
        	if(!configCode.equals("null")){
        		params.put("repeatConfigCode", configCode);
        	}
        	List<StorePackageConfigEntity> packageConfigList = packageConfigService.queryPackageConfig(params);
        	if(packageConfigList.size()>0){
        		result.put("responseCode", "11");
        	}else{
        		result.put("responseCode", "00");
        	}
		} catch (Exception e) {
			result.put("responseCode", "11");
		}
        return WrapMapper.ok(JSON.toJSONString(result));
    }
    
    @PostMapping(value = "/judgeActive/{provider}/{activeName}")
    @ApiOperation(httpMethod = "POST", value = "判断服务项目是否为医护类或者咨询类")
    public Wrapper<String> judgeActive(@ApiParam(name = "reqVo", value = "请求信息") @PathVariable String provider,
    		@ApiParam(name = "reqVo", value = "请求信息") @PathVariable String activeName){
    	Map<String, Object> result = new HashMap<String, Object>();
        try {
        	Map<String, Object> params = new HashMap<String, Object>();
        	params.put("serviceId", provider);
        	params.put("serviceCode", activeName.split("-")[0]);
        	ServiceConfigEntity serviceConfigEntity = serviceConfigService.getOneByParams(params);
        	if(PublicUtil.isNotEmpty(serviceConfigEntity)){
        		String serviceType = serviceConfigEntity.getServiceType();
        		result.put("responseCode", "1");
            	if(serviceType.equals("2")||serviceType.equals("3")){ //医护类、咨询类
            		result.put("responseCode", "1");
            	}else if(serviceType.equals("4")){ //代驾类
            		result.put("responseCode", "2");
            	}else{ //到店类
            		result.put("responseCode", "3");
            	}
            	result.put("activityType", serviceType);
        	}else{
        		result.put("responseCode", "0");
        	}
		} catch (Exception e) {
			result.put("responseCode", "0");
		}
        return WrapMapper.ok(JSON.toJSONString(result));
    }
}
